package com.xin.test2.controller;

import com.xin.test2.entity.ResponseBean;
import com.xin.test2.util.ProtoBufUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;

@Controller
public class Test2Controller {

    @PostMapping("/test2")
    @ResponseBody
    public String test2(@RequestParam("username") String username){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setUsername(username);
        responseBean.setId(1);
        byte[] bytes = ProtoBufUtil.serializer(responseBean);

        return Arrays.toString(bytes);
    }

    @GetMapping("/index")
    public String index(){
        return "test2";
    }

}
